package com.gym.myshop.common;

/**
 *@author ming
 *2021/11/6
 *description:分页
 */
public class Pages {

    private int pageIndex;
    private int pageSize;
    private int totalPage;
    private int totalCount;
    private int startRow;

    public Pages(int pageIndex, int pageSize, int totalCount) {
        //1 接受数据总条数
        this.totalCount=totalCount;
        //2 totalCount
        if (pageSize<=0) {
            this.pageSize=5;
        }else{
            this.pageSize=pageSize;
        }
        //3 计算总页数
        this.totalPage= (int) Math.ceil(this.totalCount/(this.pageSize+0.0));
        //4 当前页码的处理
        if (pageIndex<=0) {
            this.pageIndex=1;
        }else if(pageIndex>this.totalPage){
            this.pageIndex=this.totalPage;
        }else{
            this.pageIndex=pageIndex;
        }
        //5 计算起始行
        this.startRow=(this.pageIndex-1)*this.pageSize;
    }

    public Pages() {
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getStartRow() {
        return startRow;
    }

    public void setStartRow(int startRow) {
        this.startRow = startRow;
    }
}
